package com.sundae.action;


import com.sundae.beans.User;
import com.sundae.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by superace on 2017/8/5.
 */

@Controller
public class TestApiController {

    @Autowired
    private AccountService accountService;

    @RequestMapping(value = "/getJson" , method = RequestMethod.GET)
    @ResponseBody
    public String getJson(HttpServletRequest request)
    {
        String name = request.getParameter("name");
        System.out.println("name : " + name);
        return "你的名字是：" + name;
    }

    @RequestMapping(value = "/getLoginResult" , method = RequestMethod.POST)
    @ResponseBody
    public String getLoginResult(HttpServletRequest request)
    {
        String userName = request.getParameter("username");
        String passWord = request.getParameter("password");
        User user = accountService.login(userName);
        return user.toString();
    }


    @RequestMapping(value = "/getRegisterResult" , method = RequestMethod.POST)
    @ResponseBody
    public String getRegister(User user , HttpServletRequest request)
    {
        System.out.println(user.toString());
        boolean result = accountService.register(user);
        return result ? "注册成功":"注册失败";
    }

}
